#include "GuiController.h"
GuiController::GuiController(){
}
void GuiController::create_pointer(World *w)
{
	this->p_world = w;
	this->p_world->state = "Gui";
}
void GuiController::InitRocket(bool debug)
{
	#ifdef HAVE_ROCKET_PYTHON
		Py_Initialize();
	#endif  
	Rocket::Core::FontDatabase::LoadFontFace("data/fonts/Delicious-Roman.otf");
    Rocket::Core::FontDatabase::LoadFontFace("data/fonts/Delicious-Bold.otf");
    Rocket::Core::FontDatabase::LoadFontFace("data/fonts/Delicious-Italic.otf");
    Rocket::Core::FontDatabase::LoadFontFace("data/fonts/Delicious-BoldItalic.otf");
	Rocket::Core::FontDatabase::LoadFontFace("data/fonts/Naruto.ttf","Naruto",Rocket::Core::Font::STYLE_NORMAL,  Rocket::Core::Font::WEIGHT_BOLD);
//rocket handler
	r_region = RocketRegion::make("PandaRocketRegion",this->p_world->window->get_graphics_output());
	EventInstancer* event_instancer = new EventInstancer(this->p_world);
	Rocket::Core::Factory::RegisterEventListenerInstancer(event_instancer);
	r_region->set_active(1);
  //rocket input
	r_input = new RocketInputHandler();
	p_world->window->get_mouse().attach_new_node(r_input);
	r_region->set_input_handler(r_input);
	if(debug){
		Rocket::Debugger::Initialise(r_region->get_context());
		Rocket::Debugger::SetVisible(true);
	}
}
void GuiController::main_menu(bool first){ 
	if(first){
		m_menu = r_region->get_context()->LoadDocument("data/gui/Main_menu.rml");
		m_background = r_region->get_context()->LoadDocument("data/gui/background.rml");
	}
   m_menu->Show();
   m_background->Show();
 }
void GuiController::hide_main_menu(){  
   m_menu->Hide();
   m_background->Hide();
   r_region->set_active(0);
 }
void GuiController::process_gui_event(Rocket::Core::Event& event,const Rocket::Core::String& value)
{
	//printf(value.CString());
	if(value == "Play")
		p_world->state = "Play";
	if(value == "Exit")
		p_world->state = "Exit";
	if(value == "Options")
		p_world->state = "Options";

}
GuiController::~GuiController(){
}

EventInstancer::EventInstancer(World *w)
{
	this->p_world = w;
}

EventInstancer::~EventInstancer()
{
}
// Instances a new event handle for Invaders.
Rocket::Core::EventListener* EventInstancer::InstanceEventListener(const Rocket::Core::String& value)
{
	RockEvent *n = new RockEvent(value);
	n->p_world = this->p_world;
	return n;
}
// Destroys the instancer.
void EventInstancer::Release()
{
	delete this;
}